<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:job="livcos.org/ns/process/job"
  xmlns:c="livcos.org/ns/cosmos"
  xmlns:u="livcos.org/ns/cosmos/update"
  xmlns:m="livcos.org/ns/map"
  xmlns:f="livcos.org/ns/xslt/function"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="c job u m f">
  
  <xsl:import href="edit.xsl" />
  
  <xsl:param name="default_map" select="'/livcos.org/Map/data/TestMap'"/>
  
  <!-- 
    <xsl:param name="map" select="'/livcos.org/LivCos/data/pm/OpenSource/LicenseMap'"/>
    
    javascript:(function(){var a=window,d=document,e=encodeURIComponent,s=e((d.selection)?d.selection.createRange().text:getSelection()),w=a.open('http://localhost:8080/livcos/livcos.org/Map/web/add.view?u='+e(d.location)+'&t='+e(d.title)+'&s='+s,'map','resizable=1,alwaysRaised=1');a.setTimeout(function(){w.focus()},300);})()

    // netvouz
    d=document;
    te=getSelection()+'';
    t=encodeURIComponent(te);
    u=encodeURIComponent(d.location.href);
    ti=encodeURIComponent(d.title);
    if(d.referrer)r=encodeURIComponent(d.referrer);
    document.location='http://www.netvouz.com/action/submitBookmark?url='+u+'&title='+ti+'&description='+t+'&username=dreamair&popup=no';

    // Google
    javascript:(
    function(){
      var a=window,b=document,c=encodeURIComponent,
          d=a.open(%22http://www.google.com/bookmarks/mark?op=edit
                   &output=popup
                   &bkmk=%22+c(b.location)+%22
                   &title=%22+c(b.title),
                     %22bkmk_popup%22,
                     %22left=%22+((a.screenX||a.screenLeft)+10)+%22,
                     top=%22+((a.screenY||a.screenTop)+10)+%22,
                     height=420px,width=550px,resizable=1,alwaysRaised=1%22);
                   a.setTimeout(function(){d.focus()},300)})();
  
  -->
  
  <xsl:template match="/">
    <xsl:apply-templates select="*/c:request"/>
  </xsl:template>
  
  <xsl:template match="c:request">
    <xsl:variable name="itemAbsId" select="header/cookie/value[@name = 'map_item']"/>
  	<xsl:choose>
  		<xsl:when test="normalize-space($itemAbsId) != ''">
  			<xsl:variable name="itemId" select="substring-after($itemAbsId, '#')"/>
  			<xsl:variable name="mapId" select="substring-before($itemAbsId, '#')"/>
  			<xsl:call-template name="createItem">
  				<xsl:with-param name="label" select="parameter/t"/>
  				<xsl:with-param name="request" select="."/>
  				<xsl:with-param name="uri" select="parameter/u"/>
  				<xsl:with-param name="mapId" select="$mapId"/>
  				<xsl:with-param name="itemId" select="$itemId"/>
  				<xsl:with-param name="note" select="parameter/s"/>
  			</xsl:call-template>
  			<job:feed stream="response" base="job" ref="/livcos.org/Map/web/add_redirect" content-type="text/html">
  				<job:param name="map" value="{$mapId}"/>
  				<job:param name="item" value="{$itemId}"/>
  			</job:feed>
  		</xsl:when>
  		<xsl:otherwise>
  			<job:feed stream="response" content-type="text/html">
					<html>
						<body>
							<p>No map selected!</p>
							<p>Please navigate any map with this browser before you add a link!</p>
							<p>Your browser also needs to allow cookies.</p>
						</body>
					</html>
  			</job:feed>
  		</xsl:otherwise>
  	</xsl:choose>
  </xsl:template>
  
</xsl:stylesheet>
